﻿using System;
using System.ComponentModel;
using System.Net;
using AccessControl.Utility.Tools;

namespace AccessControl.HardwareLibrary
{
    public abstract class Device
    {
        public int pkDevice { get; set; }

        public IPEndPoint IP;

        public abstract string DeviceType { get; }

        public bool Connect(string ip, int port){
            return Connect(ip,port,0);
        }
        public abstract void Disconnect();

        public abstract bool Connect(string ip,int port,int failRetries);
        public event EventHandler TimeoutExpired;
        public delegate void StatusChangedEventHandler(object sender, bool connected);

        public event StatusChangedEventHandler ConnectionChanged;

        public void OnConnectionChanged(bool connected)
        {
            if (ConnectionChanged != null) ConnectionChanged(this, connected);
        }

        protected void WriteLog(string message,eventLevelConstants level){
            LogFile.WriteLog(LogFile.DefaultLogfileLocation + "HardwareLibrary\\" + DateTime.Now.Date.ToString("yyyyMMdd") + ".txt", level, IP + " " + message);
            
        }
    }
}
